package com.isoft.c2team3service2.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.c2team3service2.entity.PostArtistTag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PostArtistTagMapper extends BaseMapper<PostArtistTag> {
    /**
     * 根据艺人ID查询关联的帖子ID列表
     */
    @Select("SELECT post_id FROM post_artist_tag WHERE artist_id = #{artistId}")
    List<Integer> selectPostIdsByArtistId(Integer artistId);

    /**
     * 根据帖子ID删除所有关联的艺人标签
     */
    @Select("DELETE FROM post_artist_tag WHERE post_id = #{postId}")
    void deleteByPostId(Integer postId);

    /**
     * 根据艺人名称模糊查询关联的帖子ID（通过artist表关联）
     */
    @Select("SELECT pat.post_id " +
            "FROM post_artist_tag pat " +
            "LEFT JOIN artist a ON pat.artist_id = a.id " +
            "WHERE a.name LIKE CONCAT('%', #{artistName}, '%')")
    List<Integer> selectPostIdsByArtistNameLike(String artistName);
}